home *** CD-ROM | disk | FTP | other *** search
- Path: news.duke.edu!stking
- From: stking@acpub.duke.edu (Steve King)
- Newsgroups: comp.lang.c
- Subject: Re: Problem w/simple linked list
- Date: 19 Apr 1996 12:31:05 GMT
- Organization: Duke University, Durham, NC, USA
- Message-ID: <4l8129$23e@news.duke.edu>
- References: <4l5eha$5qa@news.duke.edu> <3176E48C.3E7B@willows.com>
- NNTP-Posting-Host: godzilla5.acpub.duke.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- : > }
- : > previous = walk;
- : > return(NULL);
-
- : You'll note that within the for loop previous is always NULL so I think
- : you want to move previous = walk into the loop.
-
- Yup. I feel like an idiot for not catching this myself. Many thanks
- to you and everyone else who pointed this out....
-
- : However this still
- : leaves you with one problem; what happens if the first node is the correct
- : one? But because you have only a singlely linked list it will be difficult
- : to properly execute if you still want to use the return value of the function
- : as the indicator. So there are two possible solutions:
-
- (Solution 1 deleted -- don't really need the advantages
- of a doubley-linked list for what I'm trying to do).
-
- But this....
-
- : 2. if you want to keep the singlely linked list then you must take into
- : account the special situation where the first node is the matching one.
- : The simplest way I can think of is to move the delete code into the
- : FindInList routine:
- : ...
- : if (strcmp(walk->patient.name,name) == 0)
- : {
- : if ( previous )
- : previous->next = walk->next;
- : free ( walk );
- : return( 1 );
- : }
- : ...
- : return ( 0 );
-
-
- I *like*! Hmmm. I was thinking about just doing something like
- using "memset()" to fill the head structure with garbage, or
- 0's, but your second solution really impresses me as being a
- clean way to handle this.
-
- Thanks, man. And again, to everyone who took his or her time to
- write.
-
-
-
- ======================================================================
- *stking@acpub.duke.edu*| Such as they are, these are my opinions only;
- *919-286-4476* | not my employer's or internet provider's....
- ======================================================================
-
-